package com.hxzy.servlet.TbPanelContent;

import com.hxzy.entity.TbPanelContent;
import com.hxzy.service.TbPanelContentService;
import com.hxzy.service.impl.TbPanelContentServiceImpl;
import org.apache.commons.beanutils.BeanUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Enumeration;
import java.util.List;

@WebServlet(urlPatterns = "/TbPanelContent/search")
public class search extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        this.doGet(req, res);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");

        TbPanelContentService service=new TbPanelContentServiceImpl();
//        List<TbPanelContent> search = service.search();
        TbPanelContent content=new TbPanelContent();
        Enumeration<String> parameterNames = req.getParameterNames();
        while (parameterNames.hasMoreElements()){
            String key = parameterNames.nextElement();
            String value = req.getParameter(key);
            if (null!=value&&value.trim().length()>0){
                try {
                    BeanUtils.setProperty(content,key,value.trim());
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                } catch (InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }

        List<TbPanelContent> search = service.searchByCondition(content);

        req.setAttribute("id",search);
        req.getRequestDispatcher("/WEB-INF/TbPanelContent/search.jsp").forward(req,res);
    }
}
